/**
 * 
 */
package com.feib.stms.service.impl;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.stereotype.Service;

import com.feib.stms.dao.ActionLogDao;
import com.feib.stms.dao.DeliveryPaymentChkDao;
import com.feib.stms.dao.DeliveryPaymentDao;
import com.feib.stms.dao.PurchasePaymentDao;
import com.feib.stms.dao.PurchaseReturnPaymentDao;
import com.feib.stms.dao.jdbc.SqlQueryMapProvider;
import com.feib.stms.dao.jdbc.SqlQueryProvider;
import com.feib.stms.model.ActionLog;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.ActionLogService;

/**
 * @author Jimmy Liu
 *
 */
@Service("actionLogService")
public class ActionLogServiceImpl extends BaseServiceImpl implements ActionLogService 
{

	private static final long serialVersionUID = -4103362979233480670L;
	
	
	@Resource(name="dataSource")
	protected DataSource dataSource;

	@Resource(name="temporaryBaseDirectory")
	protected String temporaryBaseDirectory;


	@Resource(name="actionLogDao")
	private ActionLogDao actionLogDao;

	/* (non-Javadoc)
	 * @see com.feib.stms.service.ActionLogService#addctionLog(com.feib.stms.model.ActionLog)
	 */
	public int addctionLog(ActionLog actionLog) {
		return actionLogDao.insert(actionLog);
	}

	/* (non-Javadoc)
	 * @see com.feib.stps.service.ActionLogService#findForPaginatedListByActionLog(com.feib.stps.model.ActionLog)
	 */
	public PaginatedList<ActionLog> findForPaginatedListByActionLog(ActionLog actionLog, PaginatedList paginatedList, String securitiesAsList) {
		return actionLogDao.queryForPaginatedListByActionLog(actionLog, paginatedList, securitiesAsList);
	}

	public String exportExcelByPaymentFileContent(ActionLog actionLog, PaginatedList paginatedList, String securitiesAsList) throws Exception {
		String[] headers = new String[]{"操作日期", "時間", "功能模組 ", "功能名稱", "操作內容"
				, "來源IP", "使用者ID", "分公司", };


		String sheetName = "操作紀錄查詢";
	
		SqlQueryProvider sqlQueryProvider = actionLogDao.getSqlQueryProviderByActionLog(actionLog, paginatedList, securitiesAsList);
		ActionLogContentExcelExportor exportor = new ActionLogContentExcelExportor(dataSource, sqlQueryProvider, headers, temporaryBaseDirectory, sheetName);

		String fileName = exportor.export();
		return fileName;
	}
}
